import React,{ useState } from 'react'

function Fun(){
    const [count,setCount]=useState(0);
    const [countArr,setCountArr]=useState([1,2,3]);
    const add=()=>{
        // setCount(count+1)

        // setCount(prevCount=>prevCount+2);是一个函数，拿到的永远是上一次的值，上一次执行完之后，我们才能执行第二次....
        
        
        setTimeout(()=>{
            setCount(prevCount=>prevCount+2)
        },1000);
    }

    const addAry=()=>{
        setCountArr([...countArr,4])
    }
    return (
        <div>
            {count}
            <button onClick={add}>add</button>
            <br/>
            <br/>

            {countArr.map((item,index)=><span key={index}>{item}</span>)}
            <button onClick={addAry}>加一个值</button>

        </div>
    )
}

export default Fun